home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Resources / Online / Term / Extras / Source / gtlayout-source.lha / LT_NewMenuTagList.c < prev    next >
C/C++ Source or Header  |  1996-09-23  |  10KB  |  361 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1996 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14. #ifdef DO_MENUS
  15.  
  16. /****** gtlayout.library/LT_NewMenuTagList ******************************************
  17. *
  18. *   NAME
  19. *    LT_NewMenuTagList -- Allocate and layout menu items (V11)
  20. *
  21. *   SYNOPSIS
  22. *    Menu = LT_NewMenuTagList(Tags)
  23. *     D0                       A0
  24. *
  25. *    struct Menu *LT_NewMenuTagList(struct TagItem *);
  26. *
  27. *    struct Menu *LT_NewMenuTags(...);
  28. *
  29. *   FUNCTION
  30. *    Allocates Menus and MenuItems similar to LT_LayoutMenus().
  31. *
  32. *    As of v18 this routine will validate menu mutual exclusion
  33. *    information.
  34. *
  35. *   INPUTS
  36. *    Tags - Pointer to a list of tagitem values, as found
  37. *        in gtlayout.h
  38. *
  39. *
  40. *    Valid tags include:
  41. *
  42. *    LAMN_Screen (struct Screen *) - Pointer to the Screen
  43. *        the menu is to appear upon. This tag is mandatory,
  44. *        unless the LAMN_LayoutHandle tag is used.
  45. *
  46. *    LAMN_TextAttr (struct TextAttr *) - Pointer to the
  47. *        TextAttr to use for the menu layout. If this tag
  48. *        is omitted the Screen->Font will be used.
  49. *
  50. *    LAMN_Error (LONG *) - Pointer to variable to receive
  51. *        an error in case of failure.
  52. *
  53. *    LAMN_AmigaGlyph (struct Image *) - Pointer to Image to
  54. *        use as the Amiga glyph in menus. Will be ignored if
  55. *        NULL.
  56. *
  57. *        NOTE: Ignored by intuition.library v37 and below.
  58. *
  59. *    LAMN_CheckmarkGlyph (struct Image *) - Pointer to Image to
  60. *        use as the checkmark glyph in menus. Will be ignored
  61. *        if NULL.
  62. *
  63. *    LAMN_LayoutHandle (LayoutHandle *) - Pointer to a valid
  64. *        LayoutHandle as created by LT_CreateHandle. This tag
  65. *        provides all the information the single tags
  66. *        LAMN_Screen..LAMN_CheckmarkGlyph would otherwise
  67. *        need to provide.
  68. *
  69. *    LAMN_TitleText (STRPTR) - Name of new menu to create.
  70. *        You may precede the name with the keyboard shortcut
  71. *        to assign to this menu item as follows:
  72. *
  73. *           A\0Save as...
  74. *
  75. *        This will create a menu item using the shortcut "A"
  76. *        and the title "Save as...".
  77. *
  78. *    LAMN_TitleID (LONG) - Locale ID corresponding to the
  79. *        name of the new menu to create.
  80. *        You may precede the name with the keyboard shortcut
  81. *        to assign to this menu item as follows:
  82. *
  83. *           A\0Save as...
  84. *
  85. *        This will create a menu item using the shortcut "A"
  86. *        and the title "Save as...".
  87. *
  88. *    LAMN_ItemText (STRPTR) - Name of new menu item to create.
  89. *        You may precede the name with the keyboard shortcut
  90. *        to assign to this menu item as follows:
  91. *
  92. *           A\0Save as...
  93. *
  94. *        This will create a menu item using the shortcut "A"
  95. *        and the title "Save as...".
  96. *
  97. *    LAMN_ItemID (LONG) - Locale ID corresponding to the
  98. *        name of the new menu item to create.
  99. *        You may precede the name with the keyboard shortcut
  100. *        to assign to this menu item as follows:
  101. *
  102. *           A\0Save as...
  103. *
  104. *        This will create a menu item using the shortcut "A"
  105. *        and the title "Save as...".
  106. *
  107. *    LAMN_SubText (STRPTR) - Name of new submenu item to create.
  108. *        You may precede the name with the keyboard shortcut
  109. *        to assign to this menu item as follows:
  110. *
  111. *           A\0Save as...
  112. *
  113. *        This will create a menu item using the shortcut "A"
  114. *        and the title "Save as...".
  115. *
  116. *    LAMN_SubID (LONG) - Locale ID corresponding to the
  117. *        name of the new submenu item to create.
  118. *        You may precede the name with the keyboard shortcut
  119. *        to assign to this menu item as follows:
  120. *
  121. *           A\0Save as...
  122. *
  123. *        This will create a menu item using the shortcut "A"
  124. *        and the title "Save as...".
  125. *
  126. *    LAMN_KeyText (STRPTR) - Pointer to the string whose first
  127. *        character will be used as the keyboard shortcut for
  128. *        this menu/submenu item.
  129. *
  130. *    LAMN_KeyID (LONG) - Locale ID corresponding to the string whose
  131. *        first character will be used as the keyboard shortcut for
  132. *        this menu/submenu item.
  133. *
  134. *    LAMN_CommandText (STRPTR) - Pointer to the string which
  135. *        will be used as the keyboard shortcut for this
  136. *        menu/submenu item.
  137. *
  138. *    LAMN_CommandID (LONG) - Locale ID corresponding to the string
  139. *        which will be used as the keyboard shortcut for
  140. *        this menu/submenu item.
  141. *
  142. *    LAMN_MutualExclude (ULONG) - Mutual exclusion information for
  143. *        this menu/submenu item.
  144. *
  145. *    LAMN_UserData (APTR) - User data information for this
  146. *        menu/menu item/submenu item.
  147. *
  148. *    LAMN_Disabled (BOOL) - Controls whether this
  149. *        menu/menu item/submenu item should be disabled.
  150. *
  151. *    LAMN_CheckIt (BOOL) - Controls whether this menu/submenu item
  152. *        should be prepared to hold a checkmark.
  153. *
  154. *            NOTE: This does not set the checkmark, use LAMN_Checked
  155. *                for this purpose.
  156. *
  157. *    LAMN_Checked (BOOL) - Controls whether this menu/submenu item
  158. *        should be marked with a checkmark. This tag implies
  159. *        "LAMN_Checked,TRUE".
  160. *
  161. *    LAMN_Toggle (BOOL) - Controls whether this menu/submenu item
  162. *        should be prepared to hold a checkmark the user is to
  163. *        toggle on demand. This tag implies "LAMN_Checked,TRUE".
  164. *
  165. *            NOTE: this does not set the checkmark, use LAMN_Checked
  166. *                for this purpose.
  167. *
  168. *    LAMN_Code (UWORD) - Raw key code to associate with this
  169. *        menu/submenu item. To find out if a rawkey event
  170. *        corresponds to this menu item use LT_FindMenuCommand.
  171. *
  172. *    LAMN_Qualifier (ULONG) - Key qualifier to associate
  173. *        with this menu/submenu item.
  174. *
  175. *            NOTE: the comparison does not distinguish between
  176. *                the left and right shift/caps/alt qualifier keys.
  177. *
  178. *    LAMN_ID (ULONG) - Unique ID to associate with this
  179. *        menu/menu item/submenu item. You can use this
  180. *        later to look up data using LT_GetMenuItem, etc.
  181. *
  182. *    LAMN_ExtraSpace (UWORD) - Number of pixels to put between
  183. *        neighbouring menu titles. (V18)
  184. *        Default: 0 pixels.
  185. *
  186. *   RESULT
  187. *    Menu - Pointer to Menu structure, ready to pass to
  188. *           SetMenuStrip(), NULL on failure.
  189. *
  190. *   EXAMPLE
  191. *    The following tagitem list:
  192. *
  193. *        LAMN_TitleText,     "Project"
  194. *         LAMN_ItemText,     "New",
  195. *          LAMN_KeyText,     "N",
  196. *         LAMN_ItemText,     "Open...",
  197. *          LAMN_KeyText,     "O",
  198. *         LAMN_ItemText,     NM_BARLABEL,
  199. *         LAMN_ItemText,     "Save",
  200. *          LAMN_KeyText,     "S",
  201. *         LAMN_ItemText,     "A\0Save As...",
  202. *         LAMN_ItemText,     NM_BARLABEL,
  203. *         LAMN_ItemText,     "Print...",
  204. *          LAMN_KeyText,     "P",
  205. *         LAMN_ItemText,     NM_BARLABEL,
  206. *         LAMN_ItemText,     "Help...",
  207. *          LAMN_CommandText, "[Help]",
  208. *         LAMN_ItemText,     NM_BARLABEL,
  209. *         LAMN_ItemText,     "Quit...",
  210. *          LAMN_KeyText,     "Q",
  211. *        TAG_DONE
  212. *
  213. *    Will create the following menu:
  214. *
  215. *    +-------+
  216. *    |Project|
  217. *    +-------+------+
  218. *    |New         aN|
  219. *    |Open...     aO|
  220. *    |~~~~~~~~~~~~~~|
  221. *    |Save        aS|
  222. *    |Save As...  aA|
  223. *    |~~~~~~~~~~~~~~|
  224. *    |Print...    aP|
  225. *    |~~~~~~~~~~~~~~|
  226. *    |Help... [Help]|
  227. *    |~~~~~~~~~~~~~~|
  228. *    |Quit...     aQ|
  229. *    +--------------+
  230. *
  231. *   NOTES
  232. *    You may freely add, remove, spindle & mutilate the contents of the
  233. *    menu strip created, just don't trash or disconnect the base menu
  234. *    entry this routine creates as all menu memory tracking data is
  235. *    connected to it.
  236. *
  237. *   SEE ALSO
  238. *    gtlayout.library/LT_DisposeMenu
  239. *    gtlayout.library/LT_FindCommandItem
  240. *    gtlayout.library/LT_GetMenuItem
  241. *    gtlayout.library/LT_LayoutMenuA
  242. *    gtlayout.library/LT_MenuControlTagList
  243. *    gtlayout.library/LT_NewMenuTemplate
  244. *    intuition.library/SetMenuStrip
  245. *
  246. ******************************************************************************
  247. *
  248. */
  249.  
  250. struct Menu * LIBENT
  251. LT_NewMenuTagList(REG(a0) struct TagItem *TagList)
  252. {
  253.     RootMenu        *Root;
  254.     struct Image    *AmigaGlyph    = NULL,
  255.                     *CheckGlyph = NULL;
  256.     LONG            *ErrorPtr = NULL,
  257.                      Error;
  258.     struct Screen    *Screen = NULL;
  259.     struct TextAttr    *TextAttr = NULL;
  260.     struct TagItem    *List,
  261.                     *Entry;
  262.     LayoutHandle    *Handle = NULL;
  263.     struct Hook        *LocaleHook = NULL;
  264.     LONG             ExtraSpace = 0;
  265.  
  266.     List = TagList;
  267.  
  268.     while(Entry = NextTagItem(&List))
  269.     {
  270.         switch(Entry->ti_Tag)
  271.         {
  272.             case LAMN_AmigaGlyph:
  273.  
  274.                 AmigaGlyph = (struct Image *)Entry->ti_Data;
  275.                 break;
  276.  
  277.             case LAMN_CheckmarkGlyph:
  278.  
  279.                 CheckGlyph = (struct Image *)Entry->ti_Data;
  280.                 break;
  281.  
  282.             case LAMN_Error:
  283.  
  284.                 ErrorPtr = (LONG *)Entry->ti_Data;
  285.                 break;
  286.  
  287.             case LAMN_Screen:
  288.  
  289.                 Screen = (struct Screen *)Entry->ti_Data;
  290.                 break;
  291.  
  292.             case LAMN_TextAttr:
  293.  
  294.                 TextAttr = (struct TextAttr *)Entry->ti_Data;
  295.                 break;
  296.  
  297.             case LAMN_Handle:
  298.  
  299.                 Handle        = (LayoutHandle *)Entry->ti_Data;
  300.                 Screen        = Handle->Screen;
  301.                 TextAttr    = Handle->InitialTextAttr;
  302.                 AmigaGlyph    = Handle->AmigaGlyph;
  303.                 CheckGlyph    = Handle->CheckGlyph;
  304.                 break;
  305.  
  306.             case LAMN_ExtraSpace:
  307.  
  308.                 ExtraSpace = Entry->ti_Data;
  309.                 break;
  310.  
  311.             case LH_LocaleHook:
  312.  
  313.                 LocaleHook = (struct Hook *)Entry->ti_Data;
  314.                 break;
  315.         }
  316.     }
  317.  
  318.     if(Handle)
  319.         LocaleHook = Handle->LocaleHook;
  320.  
  321.     if(ErrorPtr)
  322.         *ErrorPtr = 0;
  323.  
  324.     if(Root = LTP_NewMenu(Screen,TextAttr,AmigaGlyph,CheckGlyph,&Error))
  325.     {
  326.         Root->Handle        = Handle;
  327.         Root->LocaleHook    = LocaleHook;
  328.  
  329.             // Create the menu
  330.  
  331.         if(LTP_CreateMenuTagList(Root,&Error,TagList))
  332.         {
  333.                 // Do the layout
  334.  
  335.             if(LTP_LayoutMenu(Root,0,ExtraSpace))
  336.                 return(&Root->Menu);
  337.             else
  338.                 Error = ERROR_DISK_FULL;
  339.         }
  340.  
  341.         LT_DisposeMenu(&Root->Menu);
  342.     }
  343.  
  344.     if(ErrorPtr)
  345.         *ErrorPtr = Error;
  346.  
  347.     return(NULL);
  348. }
  349.  
  350.  
  351. /*****************************************************************************/
  352.  
  353.  
  354. struct Menu *
  355. LT_NewMenuTags(Tag FirstTag,...)
  356. {
  357.     return(LT_NewMenuTagList((struct TagItem *)&FirstTag));
  358. }
  359.  
  360. #endif    /* DO_MENUS */
  361.